//package com.zijing2333.adaptivescheduling;
//
//import android.os.Bundle;
//import android.util.Log;
//import android.view.View;
//import android.widget.Button;
//
//import androidx.appcompat.app.AppCompatActivity;
//
//import com.zijing2333.adaptivescheduling.SwitcherManager.Switcher;
//import com.zijing2333.servicerunner.TaskInfo;
//
///**
// * MainActivity class for the Adaptive Scheduling App.
// */
//public class MainActivity extends AppCompatActivity {
//
//    private static final String TAG = MainActivity.class.getSimpleName();
//
//    // Instance of the SchedulerManager for handling scheduling tasks
////    private SchedulerManager mSchedulerManager;
//
//    // Instance of the Switcher for managing execution states
//    private Switcher mSwitcher;
//
//    // Button for sending JS resources
//    private Button mSendJSResourceButton;
//
//    // Button for getting the current execution state
//    private Button mGetCurrentExecutionStateButton;
//
//    String jsResource = "<!DOCTYPE html>\n" +
//            "<html lang=\"en\">\n" +
//            "<head>\n" +
//            "    <meta charset=\"UTF-8\">\n" +
//            "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
//            "    <title>3-Minute Countdown</title>\n" +
//            "    <style>\n" +
//            "        body {\n" +
//            "            display: flex;\n" +
//            "            justify-content: center;\n" +
//            "            align-items: center;\n" +
//            "            height: 100vh;\n" +
//            "            margin: 0;\n" +
//            "            font-family: Arial, sans-serif;\n" +
//            "            background-color: #f5f5f5;\n" +
//            "        }\n" +
//            "        .countdown-container {\n" +
//            "            display: flex;\n" +
//            "            align-items: center;\n" +
//            "            justify-content: center;\n" +
//            "            width: 250px;\n" +
//            "            height: 250px;\n" +
//            "            background-color: #ffffff;\n" +
//            "            border: 5px solid #333333;\n" +
//            "            border-radius: 50%;\n" +
//            "            box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);\n" +
//            "        }\n" +
//            "        h1 {\n" +
//            "            font-size: 48px;\n" +
//            "            margin: 0;\n" +
//            "        }\n" +
//            "    </style>\n" +
//            "</head>\n" +
//            "<body>\n" +
//            "<div class=\"countdown-container\">\n" +
//            "    <h1 id=\"countdown\">3:00</h1>\n" +
//            "</div>\n" +
//            "<script>\n" +
//            "        // 设置倒计时时间（以秒为单位）\n" +
//            "        let countdownTime = 3 * 60;\n" +
//            "\n" +
//            "        // 获取页面上的倒计时元素\n" +
//            "        const countdownElement = document.getElementById(\"countdown\");\n" +
//            "\n" +
//            "        // 创建一个定时器，每秒更新一次倒计时\n" +
//            "        const countdownTimer = setInterval(() => {\n" +
//            "            countdownTime--;\n" +
//            "\n" +
//            "            // 当倒计时结束时\n" +
//            "            if (countdownTime < 0) {\n" +
//            "                clearInterval(countdownTimer);\n" +
//            "                countdownElement.innerText = \"Time's Up!\";\n" +
//            "            } else {\n" +
//            "                const minutes = Math.floor(countdownTime / 60);\n" +
//            "                const seconds = countdownTime % 60;\n" +
//            "                countdownElement.innerText = `${minutes}:${seconds.toString().padStart(2, '0')}`;\n" +
//            "            }\n" +
//            "        }, 1000);\n" +
//            "\n" +
//            "        // 保存当前倒计时剩余时间\n" +
//            "        function onSaveData() {\n" +
//            "            return countdownTime;\n" +
//            "        }\n" +
//            "\n" +
//            "        // 恢复倒计时到指定的剩余时间（以秒为单位）\n" +
//            "        function onRestore(newCountdownTime) {\n" +
//            "            countdownTime = newCountdownTime;\n" +
//            "        }\n" +
//            "    </script>\n" +
//            "</body>\n" +
//            "</html>\n";
//
//
//    /**
//     * Called when the activity is first created.
//     * @param savedInstanceState a Bundle containing the activity's previously frozen state, if there was one.
//     */
//    @Override
//    protected void  onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//
//        // Initialize SchedulerManager and Switcher instances
////        mSchedulerManager = new SchedulerManager(this);
//        mSwitcher = new Switcher(this);
//
//
//
//        // Set the content view for the activity
//        setContentView(R.layout.activity_main);
//
//        // Find and set up the Send JS Resource button
//        mSendJSResourceButton = findViewById(R.id.send_js_resource_button);
//        mSendJSResourceButton.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                // Send a sample JS resource using the SchedulerManager
//                TaskInfo taskInfo = new TaskInfo("001",jsResource,true,"");
//                boolean isSuccess = mSwitcher.dispatchJsTask("001",taskInfo);
//            }
//        });
//
//        // Find and set up the Get Current Execution State button
//        mGetCurrentExecutionStateButton = findViewById(R.id.get_current_execution_state_button);
//        mGetCurrentExecutionStateButton.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                // Get and log the current execution state using the Switcher
//
//                Log.d(TAG, "Current Execution State: " +  mSwitcher.getCurrentExecutionState("001"));
//
//            }
//        });
//
//        // Find and set up the Restore Service Data State button
//        Button mRestoreServiceDataStateButton = findViewById(R.id.restore_service_data_state_button);
//        mRestoreServiceDataStateButton.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                // Restore the service data state using the Switcher
//                String serviceId = "001";
//                mSwitcher.restoreServiceDataState(serviceId);
//            }
//        });
//
//        Button mMigrationButton = findViewById(R.id.start_migration_button);
//        mMigrationButton.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                //拉起对端的服务
//                //发送数据
//                //恢复对方的数据
//            }
//        });
//
//
////        Button mSendJSResource2Button = findViewById(R.id.send_js_resource_2_button);
////        mSendJSResource2Button.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                // Send a sample JS resource 2 using the SchedulerManager
////                mSchedulerManager.sendJSResource("02",
////                        "let countdown;\n" +
////                                "let remainingTime = 100;\n" +
////                                "\n" +
////                                "function startCountdown() {\n" +
////                                "    clearInterval(countdown);\n" +
////                                "    countdown = setInterval(() => {\n" +
////                                "        if (remainingTime <= 0) {\n" +
////                                "            if (remainingTime === 0) {\n" +
////                                "                clearInterval(countdown);\n" +
////                                "            }\n" +
////                                "        } else {\n" +
////                                "            remainingTime--;\n" +
////                                "            document.getElementById('timer').textContent = remainingTime;\n" +
////                                "        }\n" +
////                                "    }, 1000);\n" +
////                                "}\n" +
////                                "\n" +
////                                "function onSaveData() {\n" +
////                                "    return remainingTime\n" +
////                                "}\n" +
////                                "\n" +
////                                "function onRestoreData(data) {\n" +
////                                "    remainingTime = data;\n" +
////                                "    startCountdown();\n" +
////                                "}\n" +
////                                "\n" +
////                                "startCountdown();\n",false);
////            }
////        });
////
////        // Find and set up the Get Current Execution State 2 button
////        Button mGetCurrentExecutionState2Button = findViewById(R.id.get_current_execution_state_2_button);
////        mGetCurrentExecutionState2Button.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                // Get and log the current execution state 2 using the Switcher
////                Log.d(TAG, "Current Execution State 2: " + mSwitcher.getCurrentExecutionState("02",false));
////            }
////        });
////
////        // Find and set up the Restore Service Data State 2 button
////        Button mRestoreServiceDataState2Button = findViewById(R.id.restore_service_data_state2_button);
////        mRestoreServiceDataState2Button.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                // Restore the service data state 2 using the Switcher
////                String serviceId = "02";
////                mSwitcher.restoreServiceDataState(serviceId,false);
////                TaskInfo taskInfo = new TaskInfo("1", "TaskCode", true, "TaskParams");
////                System.out.println(taskInfo.toString());
////                mSwitcher.dispatchJsTask(taskInfo.getTaskId(),taskInfo);
////            }
////        });
////
////        Button mSendJSResource3Button = findViewById(R.id.send_js_resource_3_button);
////        mSendJSResource3Button.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                // Send a sample JS resource 3 using the SchedulerManager
////                mSchedulerManager.sendJSResource("03",
////                        "let countdown;\n" +
////                                "let remainingTime = 100;\n" +
////                                "\n" +
////                                "function startCountdown() {\n" +
////                                "    clearInterval(countdown);\n" +
////                                "    countdown = setInterval(() => {\n" +
////                                "        if (remainingTime <= 0) {\n" +
////                                "            if (remainingTime === 0) {\n" +
////                                "                clearInterval(countdown);\n" +
////                                "            }\n" +
////                                "        } else {\n" +
////                                "            remainingTime--;\n" +
////                                "            document.getElementById('timer').textContent = remainingTime;\n" +
////                                "        }\n" +
////                                "    }, 1000);\n" +
////                                "}\n" +
////                                "\n" +
////                                "function onSaveData() {\n" +
////                                "    return remainingTime\n" +
////                                "}\n" +
////                                "\n" +
////                                "function onRestoreData(data) {\n" +
////                                "    remainingTime = data;\n" +
////                                "    startCountdown();\n" +
////                                "}\n" +
////                                "\n" +
////                                "startCountdown();\n",false);
////            }
////        });
////
////        // Find and set up the Get Current Execution State 3 button
////        Button mGetCurrentExecutionState3Button = findViewById(R.id.get_current_execution_state_3_button);
////        mGetCurrentExecutionState3Button.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                // Get and log the current execution state 3 using the Switcher
////                Log.d(TAG, "Current Execution State 3: " + mSwitcher.getCurrentExecutionState("03",false));
////            }
////        });
////
////        // Find and set up the Restore Service Data State 3 button
////        Button mRestoreServiceDataState3Button = findViewById(R.id.restore_service_data_state3_button);
////        mRestoreServiceDataState3Button.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                // Restore the service data state 3 using the Switcher
////                String serviceId = "03";
////                mSwitcher.restoreServiceDataState(serviceId,false);
////            }
////        });
//
//    }
//
//
//}
